package emotion_codesoe_com

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/emotion_codesoe_com"
	emotion_codesoe_comReq "github.com/flipped-aurora/gin-vue-admin/server/model/emotion_codesoe_com/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type OsBannerApi struct {
}

var osBannerService = service.ServiceGroupApp.Emotion_codesoe_comServiceGroup.OsBannerService

// CreateOsBanner 创建osBanner表
// @Tags OsBanner
// @Summary 创建osBanner表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emotion_codesoe_com.OsBanner true "创建osBanner表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /osBanner/createOsBanner [post]
func (osBannerApi *OsBannerApi) CreateOsBanner(c *gin.Context) {
	var osBanner emotion_codesoe_com.OsBanner
	err := c.ShouldBindJSON(&osBanner)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := osBannerService.CreateOsBanner(&osBanner); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteOsBanner 删除osBanner表
// @Tags OsBanner
// @Summary 删除osBanner表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emotion_codesoe_com.OsBanner true "删除osBanner表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /osBanner/deleteOsBanner [delete]
func (osBannerApi *OsBannerApi) DeleteOsBanner(c *gin.Context) {
	id := c.Query("ID")
	if err := osBannerService.DeleteOsBanner(id); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteOsBannerByIds 批量删除osBanner表
// @Tags OsBanner
// @Summary 批量删除osBanner表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除osBanner表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /osBanner/deleteOsBannerByIds [delete]
func (osBannerApi *OsBannerApi) DeleteOsBannerByIds(c *gin.Context) {
	ids := c.QueryArray("ids[]")
	if err := osBannerService.DeleteOsBannerByIds(ids); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateOsBanner 更新osBanner表
// @Tags OsBanner
// @Summary 更新osBanner表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emotion_codesoe_com.OsBanner true "更新osBanner表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /osBanner/updateOsBanner [put]
func (osBannerApi *OsBannerApi) UpdateOsBanner(c *gin.Context) {
	var osBanner emotion_codesoe_com.OsBanner
	err := c.ShouldBindJSON(&osBanner)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := osBannerService.UpdateOsBanner(osBanner); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindOsBanner 用id查询osBanner表
// @Tags OsBanner
// @Summary 用id查询osBanner表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emotion_codesoe_com.OsBanner true "用id查询osBanner表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /osBanner/findOsBanner [get]
func (osBannerApi *OsBannerApi) FindOsBanner(c *gin.Context) {
	id := c.Query("ID")
	if reosBanner, err := osBannerService.GetOsBanner(id); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reosBanner": reosBanner}, c)
	}
}

// GetOsBannerListPage 分页获取osBanner表列表
// @Tags OsBanner
// @Summary 分页获取osBanner表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emotion_codesoe_comReq.OsBannerSearch true "分页获取osBanner表列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /osBanner/GetOsBannerListPage [get]
func (osBannerApi *OsBannerApi) GetOsBannerListPage(c *gin.Context) {
	var pageInfo emotion_codesoe_comReq.OsBannerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := osBannerService.GetOsBannerInfoListPage(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetOsBannerList 获取osBanner表列表
// @Tags OsBanner
// @Summary 获取osBanner表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emotion_codesoe_comReq.OsBannerSearch true "获取osBanner表列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /osBanner/getOsBannerList [get]
func (osBannerApi *OsBannerApi) GetOsBannerList(c *gin.Context) {
	var pageInfo emotion_codesoe_comReq.OsBannerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, err := osBannerService.GetOsBannerInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(gin.H{"list": list}, "获取成功", c)
	}
}
